# _*_coding:utf-8 _*_
# @Time   :2020/6/28
from rest_framework.views import APIView
from rest_framework.response import Response
from .modelsutils import *
from .permission import NeedPermission


class FindUsrByTime(APIView):
    """
    通过 用户自定义报安时间 拿到对应的用户报安信息
    """
    # throttle_scope = 'user'
    # permission_classes = [NeedPermission]

    authentication_classes = []

    permission_classes = []

    def post(self, request):
        datatime = request.data.get('time')
        info = Detail_info_filter_datatime_data(datatime)
        return Response(
            data={
                'data': info
            }
        )


class Finished(APIView):
    """
    通过 用户昵称组 减少用户的报平安天数
    """
    throttle_scope = 'user'
    permission_classes = [NeedPermission]

    def post(self, request):
        users = request.data.get('users', '')
        res = Detail_info_reduce_days(users)
        if res == 'yes':
            return Response(
                data={
                    'success': 'yes'
                }
            )
